package strategyorder

import "fmt"

// OrderProcessor 订单处理器
type OrderProcessor struct {
	discountStrategy DiscountStrategy
}

func (p *OrderProcessor) SetDiscountStrategy(strategy DiscountStrategy) {
	p.discountStrategy = strategy
}

func (p *OrderProcessor) Process(order *Order) {
	if p.discountStrategy == nil {
		p.discountStrategy = &NoDiscountStrategy{}
	}
	// 计算折扣
	discount := p.discountStrategy.CalculateDiscount(order)
	// 应用折扣
	order.DiscountAmount = discount
	order.FinalAmount = order.TotalAmount - discount
	
	// 打印订单信息
	p.printOrderDetails(order)

}

func (p *OrderProcessor) printOrderDetails(order *Order) {
	fmt.Printf("\n===== 订单 %s =====\n", order.ID)
	fmt.Printf("用户ID: %s | 用户类型: %s | 会员等级: %s\n", order.UserID, order.UserType, order.MemberLevel)
	fmt.Printf("促销活动: %s | 优惠券: %s | 是否首单: %t\n", order.Promotion, order.CouponCode, order.IsFirstOrder)

	fmt.Println("\n订单商品:")
	for _, item := range order.Items {
		fmt.Printf("- %s x%d: ¥%.2f\n", item.Name, item.Quantity, item.Price*float64(item.Quantity))
	}

	fmt.Println("\n折扣策略:", p.discountStrategy.GetDescription())
	fmt.Printf("订单总额: ¥%.2f\n", order.TotalAmount)
	fmt.Printf("折扣金额: ¥%.2f\n", order.DiscountAmount)
	fmt.Printf("最终金额: ¥%.2f\n", order.FinalAmount)
	fmt.Println("=============================")
	
}
